package org.springblade.modules.platform.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import org.springblade.modules.platform.dto.SysParameterDTO;
import org.springblade.modules.platform.entity.SysParameter;
import org.springblade.modules.platform.service.ISysParameterService;
import org.springblade.modules.platform.vo.SysParameterVO;
import org.springblade.modules.platform.vo.enums.OrdinaryPhysicalQuantityEnum;
import org.springblade.modules.platform.vo.enums.PhysicalQuantityEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author SYG
 * @since 2023-08-01
 */
@RestController
@AllArgsConstructor
@RequestMapping("/service-huateng-sxdb/sysParameter")
@Api(value = "", tags = "物理量参数")
@Slf4j
public class SysParameterController {
    private final ISysParameterService iSysParameterService;

    @GetMapping("/parameterKeyList/{measuringPlatformType}")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "物理量参数key下拉框", notes = "")
    public R parameterKeyList(@PathVariable Integer measuringPlatformType) {
        if(measuringPlatformType==1){//基础侧台
            return R.data(Arrays.asList(OrdinaryPhysicalQuantityEnum.values()));
        }else {
            return R.data(Arrays.asList(PhysicalQuantityEnum.values()));
        }
    }
    @PostMapping(value = "/install")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新增", notes = "传入sysParameterDTO")
    public R add(@RequestBody SysParameterDTO sysParameterDTO){
        iSysParameterService.add(sysParameterDTO);
        return R.success("成功");
    }
    @PostMapping(value = "/installv2")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新增", notes = "传入sysParameterDTO")
    public R add2(@RequestBody SysParameterDTO sysParameterDTO){
        iSysParameterService.remove(Wrappers.<SysParameter>lambdaQuery().eq(SysParameter::getMeasuringPlatformId,sysParameterDTO.getMeasuringPlatformId()));

        iSysParameterService.add(sysParameterDTO);
        return R.success("成功");
    }

    @PutMapping(value = "/update")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "编辑", notes = "传入sysParameterDTO")
    public R update(@RequestBody SysParameterDTO.ParameterDTO.ParameterValueDTO parameterValueDTO){
        iSysParameterService.updataSysParameter(parameterValueDTO);
        return R.success("成功");
    }

    @DeleteMapping("/remove/{id}")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "删除", notes = "传入id")
    public R remove(@PathVariable Long id){
        iSysParameterService.removeSysParameter(id);
        return R.success("成功");
    }

    @GetMapping("/info/{measuringPlatformId}")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "详情", notes = "")
    public R<SysParameterVO> getInfo(@PathVariable Long measuringPlatformId) {
        return R.data(iSysParameterService.getInfo(measuringPlatformId));
    }


}

